﻿using System;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;

namespace HslCommunication.BasicFramework
{
	/// <summary>
	/// 软件授权类
	/// </summary>
	// Token: 0x0200018A RID: 394
	public class SoftAuthorize : SoftFileSaveBase
	{
		/// <summary>
		/// 实例化一个软件授权类
		/// </summary>
		/// <param name="UseAdmin">是否使用管理员模式</param>
		// Token: 0x06002007 RID: 8199 RVA: 0x0009CB08 File Offset: 0x0009AD08
		public SoftAuthorize(bool UseAdmin = false)
		{
			this.machine_code = SoftAuthorize.GetInfo(UseAdmin);
			base.LogHeaderText = "SoftAuthorize";
		}

		/// <summary>
		/// 最终的注册秘钥信息，注意是只读的。
		/// </summary>
		/// <remarks>
		/// 时间：2018年9月1日 23:01:54，来自 洛阳-LYG 的建议，公开了本属性信息，只读。
		/// </remarks>
		// Token: 0x1700069F RID: 1695
		// (get) Token: 0x06002008 RID: 8200 RVA: 0x0009CB60 File Offset: 0x0009AD60
		// (set) Token: 0x06002009 RID: 8201 RVA: 0x0009CB68 File Offset: 0x0009AD68
		public string FinalCode { get; private set; } = "";

		/// <summary>
		/// 是否正式发行版，是的话就取消授权
		/// </summary>
		// Token: 0x170006A0 RID: 1696
		// (get) Token: 0x0600200A RID: 8202 RVA: 0x0009CB71 File Offset: 0x0009AD71
		// (set) Token: 0x0600200B RID: 8203 RVA: 0x0009CB79 File Offset: 0x0009AD79
		public bool IsReleaseVersion { get; set; } = false;

		/// <summary>
		/// 指示是否加载过文件信息
		/// </summary>
		// Token: 0x170006A1 RID: 1697
		// (get) Token: 0x0600200C RID: 8204 RVA: 0x0009CB82 File Offset: 0x0009AD82
		// (set) Token: 0x0600200D RID: 8205 RVA: 0x0009CB8A File Offset: 0x0009AD8A
		private bool HasLoadByFile { get; set; } = false;

		/// <summary>
		/// 指示系统是否处于试用运行
		/// </summary>
		// Token: 0x170006A2 RID: 1698
		// (get) Token: 0x0600200E RID: 8206 RVA: 0x0009CB93 File Offset: 0x0009AD93
		// (set) Token: 0x0600200F RID: 8207 RVA: 0x0009CB9B File Offset: 0x0009AD9B
		public bool IsSoftTrial { get; set; } = false;

		/// <summary>
		/// 获取本机的机器码
		/// </summary>
		/// <returns>机器码字符串</returns>
		// Token: 0x06002010 RID: 8208 RVA: 0x0009CBA4 File Offset: 0x0009ADA4
		public string GetMachineCodeString()
		{
			return this.machine_code;
		}

		/// <summary>
		/// 获取需要保存的数据内容
		/// </summary>
		/// <returns>实际保存的内容</returns>
		// Token: 0x06002011 RID: 8209 RVA: 0x0009CBBC File Offset: 0x0009ADBC
		public override string ToSaveString()
		{
			JObject jobject = new JObject();
			jobject.Add(SoftAuthorize.TextCode, new JValue(this.FinalCode));
			JObject jobject2 = jobject;
			return jobject2.ToString();
		}

		/// <summary>
		/// 从字符串加载数据
		/// </summary>
		/// <param name="content">文件存储的数据</param>
		// Token: 0x06002012 RID: 8210 RVA: 0x0009CBF4 File Offset: 0x0009ADF4
		public override void LoadByString(string content)
		{
			JObject json = JObject.Parse(content);
			this.FinalCode = SoftBasic.GetValueFromJsonObject<string>(json, SoftAuthorize.TextCode, this.FinalCode);
			this.HasLoadByFile = true;
		}

		/// <summary>
		/// 使用特殊加密算法加密数据
		/// </summary>
		// Token: 0x06002013 RID: 8211 RVA: 0x0009CC29 File Offset: 0x0009AE29
		public override void SaveToFile()
		{
			base.SaveToFile((string m) => SoftSecurity.MD5Encrypt(m));
		}

		/// <summary>
		/// 使用特殊解密算法解密数据
		/// </summary>
		// Token: 0x06002014 RID: 8212 RVA: 0x0009CC52 File Offset: 0x0009AE52
		public override void LoadByFile()
		{
			base.LoadByFile((string m) => SoftSecurity.MD5Decrypt(m));
		}

		/// <summary>
		/// 检查该注册码是否是正确的注册码
		/// </summary>
		/// <param name="code">注册码信息</param>
		/// <param name="encrypt">数据加密的方法，必须用户指定</param>
		/// <returns>是否注册成功</returns>
		// Token: 0x06002015 RID: 8213 RVA: 0x0009CC7C File Offset: 0x0009AE7C
		public bool CheckAuthorize(string code, Func<string, string> encrypt)
		{
			bool flag = code != encrypt(this.GetMachineCodeString());
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.FinalCode = code;
				this.SaveToFile();
				result = true;
			}
			return result;
		}

		/// <summary>
		/// 检测授权是否成功
		/// </summary>
		/// <param name="encrypt">数据加密的方法，必须用户指定</param>
		/// <returns>是否成功授权</returns>
		// Token: 0x06002016 RID: 8214 RVA: 0x0009CCBC File Offset: 0x0009AEBC
		public bool IsAuthorizeSuccess(Func<string, string> encrypt)
		{
			bool isReleaseVersion = this.IsReleaseVersion;
			bool result;
			if (isReleaseVersion)
			{
				result = true;
			}
			else
			{
				bool flag = encrypt(this.GetMachineCodeString()) == this.FinalCode;
				if (flag)
				{
					result = true;
				}
				else
				{
					this.FinalCode = "";
					this.SaveToFile();
					result = false;
				}
			}
			return result;
		}

		/// <summary>
		/// 获取本计算机唯一的机器码  
		/// </summary>
		/// <returns>字符串形式的机器码</returns>
		// Token: 0x06002017 RID: 8215 RVA: 0x0009CD14 File Offset: 0x0009AF14
		public static string GetInfo(bool UseAdmin)
		{
			string text = "";
			text = text + SoftAuthorize.HWID.BIOS + "|";
			text = text + SoftAuthorize.HWID.CPU + "|";
			text = text + SoftAuthorize.HWID.HDD + "|";
			text = text + SoftAuthorize.HWID.BaseBoard + "|";
			bool isServer = SoftAuthorize.HWID.IsServer;
			if (isServer)
			{
				text = text + SoftAuthorize.HWID.SCSI + "|";
			}
			string environmentVariable = Environment.GetEnvironmentVariable("systemdrive");
			string str = "\"" + environmentVariable + "\"";
			ManagementObject managementObject = new ManagementObject("win32_logicaldisk.deviceid=" + str);
			managementObject.Get();
			text += managementObject["VolumeSerialNumber"].ToString();
			text += "|";
			ManagementClass managementClass = new ManagementClass("Win32_ComputerSystemProduct");
			ManagementObjectCollection instances = managementClass.GetInstances();
			using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
			{
				if (enumerator.MoveNext())
				{
					ManagementObject managementObject2 = (ManagementObject)enumerator.Current;
					text += (string)managementObject2.Properties["UUID"].Value;
				}
			}
			text += "|";
			if (UseAdmin)
			{
				WindowsIdentity current = WindowsIdentity.GetCurrent();
				WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
				bool flag = windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
				bool flag2 = flag;
				if (flag2)
				{
					SoftAuthorize.HardDiskInfo hddInfo = SoftAuthorize.GetHddInfo(0);
					text += hddInfo.SerialNumber;
				}
				else
				{
					Process.Start(new ProcessStartInfo
					{
						FileName = Application.ExecutablePath,
						Verb = "runas"
					});
					Application.Exit();
				}
			}
			SHA1CryptoServiceProvider sha1CryptoServiceProvider = new SHA1CryptoServiceProvider();
			string text2 = SoftBasic.ByteToHexString(sha1CryptoServiceProvider.ComputeHash(Encoding.Unicode.GetBytes(text)));
			return text2.Substring(0, 25);
		}

		// Token: 0x06002018 RID: 8216 RVA: 0x0009CF14 File Offset: 0x0009B114
		private static string GetWMIIdent(string Class, string Property)
		{
			string result = "";
			ManagementObjectCollection instances = new ManagementClass(Class).GetInstances();
			foreach (ManagementBaseObject managementBaseObject in instances)
			{
				bool flag = (result = (managementBaseObject.GetPropertyValue(Property) as string)) != "";
				if (flag)
				{
					break;
				}
			}
			return result;
		}

		// Token: 0x06002019 RID: 8217 RVA: 0x0009CF94 File Offset: 0x0009B194
		private static string GetWMIIdent(string Class, params string[] Propertys)
		{
			string ident = "";
			Array.ForEach<string>(Propertys, delegate(string prop)
			{
				ident = ident + SoftAuthorize.GetWMIIdent(Class, prop) + " ";
			});
			return ident;
		}

		/// <summary>
		/// 获得硬盘信息
		/// </summary>
		/// <param name="driveIndex">硬盘序号</param>
		/// <returns>硬盘信息</returns>
		/// <remarks>
		/// by sunmast for everyone
		/// thanks lu0 for his great works
		/// 在Windows Array8/ME中，S.M.A.R.T并不缺省安装，请将SMARTVSD.VXD拷贝到%SYSTEM%＼IOSUBSYS目录下。
		/// 在Windows 2000/2003下，需要Administrators组的权限。
		/// </remarks>
		/// <example>
		/// AtapiDevice.GetHddInfo()
		/// </example>
		// Token: 0x0600201A RID: 8218 RVA: 0x0009CFD8 File Offset: 0x0009B1D8
		public static SoftAuthorize.HardDiskInfo GetHddInfo(byte driveIndex = 0)
		{
			SoftAuthorize.HardDiskInfo result;
			switch (Environment.OSVersion.Platform)
			{
			case PlatformID.Win32S:
				throw new NotSupportedException("Win32s is not supported.");
			case PlatformID.Win32Windows:
				result = SoftAuthorize.GetHddInfoArrayx(driveIndex);
				break;
			case PlatformID.Win32NT:
				result = SoftAuthorize.GetHddInfoNT(driveIndex);
				break;
			case PlatformID.WinCE:
				throw new NotSupportedException("WinCE is not supported.");
			default:
				throw new NotSupportedException("Unknown Platform.");
			}
			return result;
		}

		// Token: 0x0600201B RID: 8219 RVA: 0x0009D040 File Offset: 0x0009B240
		private static SoftAuthorize.HardDiskInfo GetHardDiskInfo(SoftAuthorize.IdSector phdinfo)
		{
			SoftAuthorize.HardDiskInfo result = default(SoftAuthorize.HardDiskInfo);
			SoftAuthorize.ChangeByteOrder(phdinfo.sModelNumber);
			result.ModuleNumber = Encoding.ASCII.GetString(phdinfo.sModelNumber).Trim();
			SoftAuthorize.ChangeByteOrder(phdinfo.sFirmwareRev);
			result.Firmware = Encoding.ASCII.GetString(phdinfo.sFirmwareRev).Trim();
			SoftAuthorize.ChangeByteOrder(phdinfo.sSerialNumber);
			result.SerialNumber = Encoding.ASCII.GetString(phdinfo.sSerialNumber).Trim();
			result.Capacity = phdinfo.ulTotalAddressableSectors / 2U / 1024U;
			return result;
		}

		// Token: 0x0600201C RID: 8220 RVA: 0x0009D0E8 File Offset: 0x0009B2E8
		private static SoftAuthorize.HardDiskInfo GetHddInfoArrayx(byte driveIndex)
		{
			SoftAuthorize.GetVersionOutParams getVersionOutParams = default(SoftAuthorize.GetVersionOutParams);
			SoftAuthorize.SendCmdInParams structure = default(SoftAuthorize.SendCmdInParams);
			SoftAuthorize.SendCmdOutParams sendCmdOutParams = default(SoftAuthorize.SendCmdOutParams);
			uint num = 0U;
			IntPtr intPtr = SoftAuthorize.CreateFile("＼＼.＼Smartvsd", FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero);
			bool flag = intPtr == IntPtr.Zero;
			if (flag)
			{
				throw new Exception("Open smartvsd.vxd failed.");
			}
			bool flag2 = SoftAuthorize.DeviceIoControl(intPtr, 475264U, IntPtr.Zero, 0U, ref getVersionOutParams, (uint)Marshal.SizeOf<SoftAuthorize.GetVersionOutParams>(getVersionOutParams), ref num, IntPtr.Zero) == 0;
			if (flag2)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception("DeviceIoControl failed:DFP_GET_VERSION");
			}
			bool flag3 = (getVersionOutParams.fCapabilities & 1U) == 0U;
			if (flag3)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception("Error: IDE identify command not supported.");
			}
			bool flag4 = (driveIndex & 1) > 0;
			if (flag4)
			{
				structure.irDriveRegs.bDriveHeadReg = 176;
			}
			else
			{
				structure.irDriveRegs.bDriveHeadReg = 160;
			}
			bool flag5 = ((ulong)getVersionOutParams.fCapabilities & (ulong)((long)(16 >> (int)driveIndex))) > 0UL;
			if (flag5)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception(string.Format("Drive {0} is a ATAPI device, we don’t detect it", (int)(driveIndex + 1)));
			}
			structure.irDriveRegs.bCommandReg = 236;
			structure.bDriveNumber = driveIndex;
			structure.irDriveRegs.bSectorCountReg = 1;
			structure.irDriveRegs.bSectorNumberReg = 1;
			structure.cBufferSize = 512U;
			bool flag6 = SoftAuthorize.DeviceIoControl(intPtr, 508040U, ref structure, (uint)Marshal.SizeOf<SoftAuthorize.SendCmdInParams>(structure), ref sendCmdOutParams, (uint)Marshal.SizeOf<SoftAuthorize.SendCmdOutParams>(sendCmdOutParams), ref num, IntPtr.Zero) == 0;
			if (flag6)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception("DeviceIoControl failed: DFP_RECEIVE_DRIVE_DATA");
			}
			SoftAuthorize.CloseHandle(intPtr);
			return SoftAuthorize.GetHardDiskInfo(sendCmdOutParams.bBuffer);
		}

		// Token: 0x0600201D RID: 8221 RVA: 0x0009D2B8 File Offset: 0x0009B4B8
		private static SoftAuthorize.HardDiskInfo GetHddInfoNT(byte driveIndex)
		{
			SoftAuthorize.GetVersionOutParams getVersionOutParams = default(SoftAuthorize.GetVersionOutParams);
			SoftAuthorize.SendCmdInParams structure = default(SoftAuthorize.SendCmdInParams);
			SoftAuthorize.SendCmdOutParams sendCmdOutParams = default(SoftAuthorize.SendCmdOutParams);
			uint num = 0U;
			IntPtr intPtr = SoftAuthorize.CreateFile("\\\\.\\PhysicalDrive0", FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, FileAttributes.Normal, IntPtr.Zero);
			bool flag = intPtr == IntPtr.Zero;
			if (flag)
			{
				throw new Exception("CreateFile faild.");
			}
			bool flag2 = SoftAuthorize.DeviceIoControl(intPtr, 475264U, IntPtr.Zero, 0U, ref getVersionOutParams, (uint)Marshal.SizeOf<SoftAuthorize.GetVersionOutParams>(getVersionOutParams), ref num, IntPtr.Zero) == 0;
			if (flag2)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception(string.Format("Drive {0} may not exists.", (int)(driveIndex + 1)));
			}
			bool flag3 = (getVersionOutParams.fCapabilities & 1U) == 0U;
			if (flag3)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception("Error: IDE identify command not supported.");
			}
			bool flag4 = (driveIndex & 1) > 0;
			if (flag4)
			{
				structure.irDriveRegs.bDriveHeadReg = 176;
			}
			else
			{
				structure.irDriveRegs.bDriveHeadReg = 160;
			}
			bool flag5 = ((ulong)getVersionOutParams.fCapabilities & (ulong)((long)(16 >> (int)driveIndex))) > 0UL;
			if (flag5)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception(string.Format("Drive {0} is a ATAPI device, we don’t detect it.", (int)(driveIndex + 1)));
			}
			structure.irDriveRegs.bCommandReg = 236;
			structure.bDriveNumber = driveIndex;
			structure.irDriveRegs.bSectorCountReg = 1;
			structure.irDriveRegs.bSectorNumberReg = 1;
			structure.cBufferSize = 512U;
			bool flag6 = SoftAuthorize.DeviceIoControl(intPtr, 508040U, ref structure, (uint)Marshal.SizeOf<SoftAuthorize.SendCmdInParams>(structure), ref sendCmdOutParams, (uint)Marshal.SizeOf<SoftAuthorize.SendCmdOutParams>(sendCmdOutParams), ref num, IntPtr.Zero) == 0;
			if (flag6)
			{
				SoftAuthorize.CloseHandle(intPtr);
				throw new Exception("DeviceIoControl failed: DFP_RECEIVE_DRIVE_DATA");
			}
			SoftAuthorize.CloseHandle(intPtr);
			return SoftAuthorize.GetHardDiskInfo(sendCmdOutParams.bBuffer);
		}

		// Token: 0x0600201E RID: 8222 RVA: 0x0009D498 File Offset: 0x0009B698
		private static void ChangeByteOrder(byte[] charArray)
		{
			for (int i = 0; i < charArray.Length; i += 2)
			{
				byte b = charArray[i];
				charArray[i] = charArray[i + 1];
				charArray[i + 1] = b;
			}
		}

		/// <summary>
		/// 执行打开/建立资源的功能。
		/// </summary>
		/// <param name="lpFileName">指定要打开的设备或文件的名称。</param>
		/// <param name="dwDesiredAccess">
		/// <para>Win32 常量，用于控制对设备的读访问、写访问或读/写访问的常数。内容如下表：
		/// <p><list type="table">
		/// <listheader>
		/// <term>名称</term>
		/// <description>说明</description>
		/// </listheader>
		/// <item>
		/// <term>GENERIC_READ</term><description>指定对设备进行读取访问。</description>
		/// </item>
		/// <item>
		/// <term>GENERIC_WRITE</term><description>指定对设备进行写访问。</description>
		/// </item>
		/// <item><term><b>0</b></term><description>如果值为零，则表示只允许获取与一个设备有关的信息。</description></item>
		/// </list></p>
		/// </para>
		/// </param>
		/// <param name="dwShareMode">指定打开设备时的文件共享模式</param>
		/// <param name="lpSecurityAttributes"></param>
		/// <param name="dwCreationDisposition">Win32 常量，指定操作系统打开文件的方式。内容如下表：
		/// <para><p>
		/// <list type="table">
		/// <listheader><term>名称</term><description>说明</description></listheader>
		/// <item>
		/// <term>CREATE_NEW</term>
		/// <description>指定操作系统应创建新文件。如果文件存在，则抛出 <see cref="T:System.IO.IOException" /> 异常。</description>
		/// </item>
		/// <item><term>CREATE_ALWAYS</term><description>指定操作系统应创建新文件。如果文件已存在，它将被改写。</description></item>
		/// </list>
		/// </p></para>
		/// </param>
		/// <param name="dwFlagsAndAttributes"></param>
		/// <param name="hTemplateFile"></param>
		/// <returns>使用函数打开的设备的句柄。</returns>
		/// <remarks>
		/// 本函数可以执行打开或建立文件、文件流、目录/文件夹、物理磁盘、卷、系统控制的缓冲区、磁带设备、
		/// 通信资源、邮件系统和命名管道。
		/// </remarks>
		// Token: 0x0600201F RID: 8223
		[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
		private static extern IntPtr CreateFile(string lpFileName, [MarshalAs(UnmanagedType.U4)] FileAccess dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] FileShare dwShareMode, IntPtr lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] FileMode dwCreationDisposition, [MarshalAs(UnmanagedType.U4)] FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);

		/// <summary>
		/// 关闭一个指定的指针对象指向的设备。。
		/// </summary>
		/// <param name="hObject">要关闭的句柄 <see cref="T:System.IntPtr" /> 对象。</param>
		/// <returns>成功返回 <b>0</b> ，不成功返回非零值。</returns>
		// Token: 0x06002020 RID: 8224
		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern int CloseHandle(IntPtr hObject);

		/// <summary>
		/// 对设备执行指定的操作。
		/// </summary>
		/// <param name="hDevice">要执行操作的设备句柄。</param>
		/// <param name="dwIoControlCode">Win32 API 常数，输入的是以 <b>FSCTL_</b> 为前缀的常数，定义在
		/// <b>WinIoCtl.h</b> 文件内，执行此重载方法必须输入 <b>SMART_GET_VERSION</b> 。</param>
		/// <param name="lpInBuffer">当参数为指针时，默认的输入值是 <b>0</b> 。</param>
		/// <param name="nInBufferSize">输入缓冲区的字节数量。</param>
		/// <param name="lpOutBuffer">一个 <b>GetVersionOutParams</b> ，表示执行函数后输出的设备检查。</param>
		/// <param name="nOutBufferSize">输出缓冲区的字节数量。</param>
		/// <param name="lpBytesReturned">实际装载到输出缓冲区的字节数量。</param>
		/// <param name="lpOverlapped">同步操作控制，一般不使用，默认值为 <b>0</b> 。</param>
		/// <returns>非零表示成功，零表示失败。</returns>
		// Token: 0x06002021 RID: 8225
		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern int DeviceIoControl(IntPtr hDevice, uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize, ref SoftAuthorize.GetVersionOutParams lpOutBuffer, uint nOutBufferSize, ref uint lpBytesReturned, [Out] IntPtr lpOverlapped);

		/// <summary>
		/// 对设备执行指定的操作。
		/// </summary>
		/// <param name="hDevice">要执行操作的设备句柄。</param>
		/// <param name="dwIoControlCode">Win32 API 常数，输入的是以 <b>FSCTL_</b> 为前缀的常数，定义在
		/// <b>WinIoCtl.h</b> 文件内，执行此重载方法必须输入 <b>SMART_SEND_DRIVE_COMMAND</b> 或 <b>SMART_RCV_DRIVE_DATA</b> 。</param>
		/// <param name="lpInBuffer">一个 <b>SendCmdInParams</b> 结构，它保存向系统发送的查询要求具体命令的数据结构。</param>
		/// <param name="nInBufferSize">输入缓冲区的字节数量。</param>
		/// <param name="lpOutBuffer">一个 <b>SendCmdOutParams</b> 结构，它保存系统根据命令返回的设备相信信息二进制数据。</param>
		/// <param name="nOutBufferSize">输出缓冲区的字节数量。</param>
		/// <param name="lpBytesReturned">实际装载到输出缓冲区的字节数量。</param>
		/// <param name="lpOverlapped">同步操作控制，一般不使用，默认值为 <b>0</b> 。</param>
		/// <returns>非零表示成功，零表示失败。</returns>
		// Token: 0x06002022 RID: 8226
		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern int DeviceIoControl(IntPtr hDevice, uint dwIoControlCode, ref SoftAuthorize.SendCmdInParams lpInBuffer, uint nInBufferSize, ref SoftAuthorize.SendCmdOutParams lpOutBuffer, uint nOutBufferSize, ref uint lpBytesReturned, [Out] IntPtr lpOverlapped);

		/// <summary>
		/// 注册码描述文本
		/// </summary>
		// Token: 0x0400079F RID: 1951
		public static readonly string TextCode = "Code";

		// Token: 0x040007A3 RID: 1955
		private string machine_code = "";

		// Token: 0x040007A5 RID: 1957
		private const uint DFP_GET_VERSION = 475264U;

		// Token: 0x040007A6 RID: 1958
		private const uint DFP_SEND_DRIVE_COMMAND = 508036U;

		// Token: 0x040007A7 RID: 1959
		private const uint DFP_RECEIVE_DRIVE_DATA = 508040U;

		// Token: 0x040007A8 RID: 1960
		private const uint GENERIC_READ = 2147483648U;

		// Token: 0x040007A9 RID: 1961
		private const uint GENERIC_WRITE = 1073741824U;

		// Token: 0x040007AA RID: 1962
		private const uint FILE_SHARE_READ = 1U;

		// Token: 0x040007AB RID: 1963
		private const uint FILE_SHARE_WRITE = 2U;

		// Token: 0x040007AC RID: 1964
		private const uint CREATE_NEW = 1U;

		// Token: 0x040007AD RID: 1965
		private const uint OPEN_EXISTING = 3U;

		// Token: 0x0200089E RID: 2206
		private class HWID
		{
			// Token: 0x170006DA RID: 1754
			// (get) Token: 0x0600353E RID: 13630 RVA: 0x0011EA30 File Offset: 0x0011CC30
			public static string BIOS
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_BIOS", new string[]
					{
						"Manufacturer",
						"SerialNumber",
						"SMBIOSBIOSVersion",
						"IdentificationCode"
					});
				}
			}

			// Token: 0x170006DB RID: 1755
			// (get) Token: 0x0600353F RID: 13631 RVA: 0x0011EA74 File Offset: 0x0011CC74
			public static string CPU
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_Processor", new string[]
					{
						"ProcessorId",
						"UniqueId",
						"Name"
					});
				}
			}

			// Token: 0x170006DC RID: 1756
			// (get) Token: 0x06003540 RID: 13632 RVA: 0x0011EAB0 File Offset: 0x0011CCB0
			public static string HDD
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_DiskDrive", new string[]
					{
						"Model",
						"TotalHeads"
					});
				}
			}

			// Token: 0x170006DD RID: 1757
			// (get) Token: 0x06003541 RID: 13633 RVA: 0x0011EAE4 File Offset: 0x0011CCE4
			public static string GPU
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_VideoController", new string[]
					{
						"DriverVersion",
						"Name"
					});
				}
			}

			// Token: 0x170006DE RID: 1758
			// (get) Token: 0x06003542 RID: 13634 RVA: 0x0011EB18 File Offset: 0x0011CD18
			public static string MAC
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_NetworkAdapterConfiguration", "MACAddress");
				}
			}

			// Token: 0x170006DF RID: 1759
			// (get) Token: 0x06003543 RID: 13635 RVA: 0x0011EB3C File Offset: 0x0011CD3C
			public static string OS
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_OperatingSystem", new string[]
					{
						"SerialNumber",
						"Name"
					});
				}
			}

			// Token: 0x170006E0 RID: 1760
			// (get) Token: 0x06003544 RID: 13636 RVA: 0x0011EB70 File Offset: 0x0011CD70
			public static string SCSI
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_SCSIController", new string[]
					{
						"DeviceID",
						"Name"
					});
				}
			}

			// Token: 0x170006E1 RID: 1761
			// (get) Token: 0x06003545 RID: 13637 RVA: 0x0011EBA4 File Offset: 0x0011CDA4
			public static string BaseBoard
			{
				get
				{
					return SoftAuthorize.GetWMIIdent("Win32_BaseBoard", new string[]
					{
						"SerialNumber",
						"PartNumber"
					});
				}
			}

			// Token: 0x170006E2 RID: 1762
			// (get) Token: 0x06003546 RID: 13638 RVA: 0x0011EBD8 File Offset: 0x0011CDD8
			public static bool IsServer
			{
				get
				{
					return SoftAuthorize.HWID.HDD.Contains("SCSI");
				}
			}
		}

		// Token: 0x0200089F RID: 2207
		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		internal struct SendCmdInParams
		{
			// Token: 0x0400378D RID: 14221
			public uint cBufferSize;

			// Token: 0x0400378E RID: 14222
			public SoftAuthorize.IdeRegs irDriveRegs;

			// Token: 0x0400378F RID: 14223
			public byte bDriveNumber;

			// Token: 0x04003790 RID: 14224
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
			public byte[] bReserved;

			// Token: 0x04003791 RID: 14225
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
			public uint[] dwReserved;

			// Token: 0x04003792 RID: 14226
			public byte bBuffer;
		}

		// Token: 0x020008A0 RID: 2208
		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		internal struct DriverStatus
		{
			// Token: 0x04003793 RID: 14227
			public byte bDriverError;

			// Token: 0x04003794 RID: 14228
			public byte bIDEStatus;

			// Token: 0x04003795 RID: 14229
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
			public byte[] bReserved;

			// Token: 0x04003796 RID: 14230
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
			public uint[] dwReserved;
		}

		// Token: 0x020008A1 RID: 2209
		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		internal struct SendCmdOutParams
		{
			// Token: 0x04003797 RID: 14231
			public uint cBufferSize;

			// Token: 0x04003798 RID: 14232
			public SoftAuthorize.DriverStatus DriverStatus;

			// Token: 0x04003799 RID: 14233
			public SoftAuthorize.IdSector bBuffer;
		}

		/// <summary>
		/// 硬盘信息
		/// </summary>
		// Token: 0x020008A2 RID: 2210
		[Serializable]
		public struct HardDiskInfo
		{
			/// <summary>
			/// 型号
			/// </summary>
			// Token: 0x0400379A RID: 14234
			public string ModuleNumber;

			/// <summary>
			/// 固件版本
			/// </summary>
			// Token: 0x0400379B RID: 14235
			public string Firmware;

			/// <summary>
			/// 序列号
			/// </summary>
			// Token: 0x0400379C RID: 14236
			public string SerialNumber;

			/// <summary>
			/// 容量，以M为单位
			/// </summary>
			// Token: 0x0400379D RID: 14237
			public uint Capacity;
		}

		// Token: 0x020008A3 RID: 2211
		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		internal struct GetVersionOutParams
		{
			// Token: 0x0400379E RID: 14238
			public byte bVersion;

			// Token: 0x0400379F RID: 14239
			public byte bRevision;

			// Token: 0x040037A0 RID: 14240
			public byte bReserved;

			// Token: 0x040037A1 RID: 14241
			public byte bIDEDeviceMap;

			// Token: 0x040037A2 RID: 14242
			public uint fCapabilities;

			// Token: 0x040037A3 RID: 14243
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
			public uint[] dwReserved;
		}

		// Token: 0x020008A4 RID: 2212
		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		internal struct IdeRegs
		{
			// Token: 0x040037A4 RID: 14244
			public byte bFeaturesReg;

			// Token: 0x040037A5 RID: 14245
			public byte bSectorCountReg;

			// Token: 0x040037A6 RID: 14246
			public byte bSectorNumberReg;

			// Token: 0x040037A7 RID: 14247
			public byte bCylLowReg;

			// Token: 0x040037A8 RID: 14248
			public byte bCylHighReg;

			// Token: 0x040037A9 RID: 14249
			public byte bDriveHeadReg;

			// Token: 0x040037AA RID: 14250
			public byte bCommandReg;

			// Token: 0x040037AB RID: 14251
			public byte bReserved;
		}

		// Token: 0x020008A5 RID: 2213
		[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 512)]
		internal struct IdSector
		{
			// Token: 0x040037AC RID: 14252
			public ushort wGenConfig;

			// Token: 0x040037AD RID: 14253
			public ushort wNumCyls;

			// Token: 0x040037AE RID: 14254
			public ushort wReserved;

			// Token: 0x040037AF RID: 14255
			public ushort wNumHeads;

			// Token: 0x040037B0 RID: 14256
			public ushort wBytesPerTrack;

			// Token: 0x040037B1 RID: 14257
			public ushort wBytesPerSector;

			// Token: 0x040037B2 RID: 14258
			public ushort wSectorsPerTrack;

			// Token: 0x040037B3 RID: 14259
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
			public ushort[] wVendorUnique;

			// Token: 0x040037B4 RID: 14260
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
			public byte[] sSerialNumber;

			// Token: 0x040037B5 RID: 14261
			public ushort wBufferType;

			// Token: 0x040037B6 RID: 14262
			public ushort wBufferSize;

			// Token: 0x040037B7 RID: 14263
			public ushort wECCSize;

			// Token: 0x040037B8 RID: 14264
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
			public byte[] sFirmwareRev;

			// Token: 0x040037B9 RID: 14265
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
			public byte[] sModelNumber;

			// Token: 0x040037BA RID: 14266
			public ushort wMoreVendorUnique;

			// Token: 0x040037BB RID: 14267
			public ushort wDoubleWordIO;

			// Token: 0x040037BC RID: 14268
			public ushort wCapabilities;

			// Token: 0x040037BD RID: 14269
			public ushort wReserved1;

			// Token: 0x040037BE RID: 14270
			public ushort wPIOTiming;

			// Token: 0x040037BF RID: 14271
			public ushort wDMATiming;

			// Token: 0x040037C0 RID: 14272
			public ushort wBS;

			// Token: 0x040037C1 RID: 14273
			public ushort wNumCurrentCyls;

			// Token: 0x040037C2 RID: 14274
			public ushort wNumCurrentHeads;

			// Token: 0x040037C3 RID: 14275
			public ushort wNumCurrentSectorsPerTrack;

			// Token: 0x040037C4 RID: 14276
			public uint ulCurrentSectorCapacity;

			// Token: 0x040037C5 RID: 14277
			public ushort wMultSectorStuff;

			// Token: 0x040037C6 RID: 14278
			public uint ulTotalAddressableSectors;

			// Token: 0x040037C7 RID: 14279
			public ushort wSingleWordDMA;

			// Token: 0x040037C8 RID: 14280
			public ushort wMultiWordDMA;

			// Token: 0x040037C9 RID: 14281
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
			public byte[] bReserved;
		}
	}
}
